package com.kfirszt.elearning.persistence.dao;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Repository;

import com.kfirszt.elearning.persistence.model.BaseUser;

@Repository("userDAO")
public class UserDAOImpl extends GenericDAOImpl<BaseUser, Long> implements UserDAO {

	@Override
	public Class<BaseUser> getEntityClass() {
		return BaseUser.class;
	}

	@Override
	public UserDetails findByUsername(String username) {
		DetachedCriteria criteria = DetachedCriteria.forClass(BaseUser.class);
		criteria.add(Restrictions.eq("username", username));
		List list = hibernateTemplate.findByCriteria(criteria);
		if(list.isEmpty() == false)
			return (UserDetails) list.get(0);
		return null;
	}


}
